<template>
	<view class="commodity" :style="'flex-wrap:'+wrap+';'">
		<!-- 单个商品组件 -->
		<view 
		class="commodity-item" 
		:style="'width:'+itemW+';'" 
		v-for="Commodityitem in CommodityObj" 
		:key="Commodityitem.id"
		@click="goDetail(Commodityitem.id)"
		>
			<image class="commodity-img" :style="'height:'+itemW+';'" :src="Commodityitem.imgUrl" mode=""></image>
			<view class="comodity-content">
				<text class="comodity-name">{{Commodityitem.content}}</text>
				<view>
					<text class="pprice">￥{{Commodityitem.pprice}}</text>
				</view>
				<text v-if="Commodityitem.discount!=0" class="discount"> {{Commodityitem.discount}}折</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		props:{
			CommodityObj:Array,
			itemW:{
				type:String,
				default:'355rpx'
			},
			wrap:{
				type:String,
				default:'wrap'
			}
		},
		methods:{
			// 点击商品标签跳转的方法
			goDetail(id){
				uni.navigateTo({
					url:'../../pages/details/details?id='+id+''
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.commodity{
		background-color: #e2e2e2;
		display: flex;
		// flex-wrap: wrap;
		.commodity-item{
			overflow: hidden;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			margin: 10rpx;
			padding-bottom: 20rpx;
			.commodity-img{
				width: 100%;
			}
		}
		.comodity-content{
			
			text-align: center;
			.comodity-name{
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp:2;
				-webkit-box-orient:vertical;
				color: #333333;
				word-break: break-all;
				padding: 6rpx 20rpx;
			}
			.pprice{
				color: #000000;
			}
			.oprice{
				
				color: #848484;
				font-size: 26rpx;
			}
			.discount{
				border: 4rpx solid #FF3333;
				border-radius: 8rpx;
				padding: 2rpx 10rpx;
				font-size: 20rpx;
				color: #FF3333;
			}
		}
	}
</style>
